package com.guoxin.concurrentprogramming.chapter2;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.Vector;

/**
 * @author guoxin
 * @date 2019/7/15
 */
public class ArrayListMultiThread extends Thread {
    private static final List<Integer> AL = new Vector<>();
    private static final Random R = new Random();

    @Override
    public void run() {
        for (int i = 0; i < 1000000; i++) {
            AL.add(R.nextInt(1000));
        }
    }

    public static void main(String[] args) throws InterruptedException {
        ArrayListMultiThread amt = new ArrayListMultiThread();
        Thread t1 = new Thread(amt, "T1");
        Thread t2 = new Thread(amt, "T2");
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        System.out.println(AL.size());
    }
}
